﻿using System;
using System.Data;
using System.Data.SqlClient;

namespace FluentSql
{
    public class DalSqlTransaction : IDisposable, IDalSqlTransaction
    {
        #region Public Constructors

        public DalSqlTransaction(SqlTransaction iTransaction, DalSqlConnection iGraceConnection)
        {
            Transaction = iTransaction;
            GraceConnection = iGraceConnection;
        }

        #endregion Public Constructors

        #region Public Properties

        public DalSqlConnection GraceConnection { get; private set; }

        public SqlTransaction Transaction { get; private set; }

        #endregion Public Properties

        #region Public Methods

        public void Commit()
        {
            Transaction.Commit();
        }

        public DalSqlCommand CreateCommand(string iCommandText)
        {
            return new DalSqlCommand(iCommandText, GraceConnection, this);
        }

        public DalSqlCommand CreateCommand(CommandType iCommandType, string iCommandText)
        {
            return new DalSqlCommand(iCommandType, iCommandText, GraceConnection, this);
        }

        public void Dispose()
        {
            Transaction.Dispose();
        }

        #endregion Public Methods
    }
}
